﻿#include "PyFITKMaterialsIsotropicSolids.h"
#include "FITKAcousticsMaterialsIsosolid.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsMaterial.h"


namespace Acoustics
{
    PyFITKMaterialsIsotropicSolids::PyFITKMaterialsIsotropicSolids(const QString & name) :
        Acoustics::PyFITKMaterialsBase(name)
    {
    }

    bool PyFITKMaterialsIsotropicSolids::setIsotropicSolidsProp(double density, double tensileModulus, double shearModulus, double poissonRatio)
    {
        if (!_material)return false;
        if(density<0|| tensileModulus <=0|| shearModulus <=0|| poissonRatio <=0)return false;
        if(2*shearModulus> tensileModulus|| tensileModulus >3*shearModulus)return false;
        if (poissonRatio >= 0.5)return false;

        FITKAcousticsMaterialsIsosolid *isosolid = dynamic_cast<Acoustics::FITKAcousticsMaterialsIsosolid*>(_material);
        if (!isosolid)return false;

        isosolid->setDensity(density);
        isosolid->setTensileModulus(tensileModulus);
        isosolid->setShearModulus(shearModulus);
        isosolid->setPoissonRatio(poissonRatio);
        return true;
    }

    bool PyFITKMaterialsIsotropicSolids::createMaterial(const QString & name)
    {
        if (name == "")return false;
        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
        if (matMgr == nullptr) return false;
        if (matMgr->getDataByName(name))return false;

        FITKAcousticsMaterialsIsosolid *isosolid = new FITKAcousticsMaterialsIsosolid();
        isosolid->setDataObjectName(name);
        _material = isosolid;
        matMgr->appendDataObj(_material);

        return true;
    }
}